#include <type_traits>
#include <iostream>

// 添加一个测试用的函数
void testFunction()
{
    std::cout << "Test function called!" << std::endl;
}

template <typename F>
class SimpFunction
{
public:
    // 使用decay将函数或函数指针 变为函数指针 更加通用 F就可以是函数或者函数指针类型都可以
    using FnType = typename std::decay<F>::type;
    // using FnType = F;
    SimpFunction(F f) : m_fn(f)
    {
    }

    void Run()
    {
        m_fn();
    }

private:
    FnType m_fn; //
};

int main()
{
    typedef std::decay<int>::type A;         // int
    typedef std::decay<int &>::type B;       // int
    typedef std::decay<int &&>::type C;      // int
    typedef std::decay<const int &>::type D; // int
    typedef std::decay<int[2]>::type E;      // int*
    typedef std::decay<int(int)>::type F;    // int (*)(int)

    // 使用 is_same 验证类型
    std::cout << std::boolalpha;
    std::cout << "A is int: " << std::is_same<A, int>::value << std::endl;
    std::cout << "B is int: " << std::is_same<B, int>::value << std::endl;
    std::cout << "C is int: " << std::is_same<C, int>::value << std::endl;
    std::cout << "D is int: " << std::is_same<D, int>::value << std::endl;
    std::cout << "E is int*: " << std::is_same<E, int *>::value << std::endl;
    std::cout << "F is int(*)(int): " << std::is_same<F, int (*)(int)>::value << std::endl;

    // 测试 SimpFunction
    std::cout << "\nTesting SimpFunction:\n";
    SimpFunction<void (*)()> func(testFunction);
    func.Run(); // 应该输出 "Test function called!"

    // 添加 conditional 测试
    typedef std::conditional<true, int, float>::type Type1;                          // int
    typedef std::conditional<false, int, float>::type Type2;                         // float
    typedef std::conditional<std::is_integral<Type1>::value, long, int>::type Type3; // long
    typedef std::conditional<std::is_integral<Type2>::value, long, int>::type Type4; // int
    typedef std::conditional<(sizeof(long long) > sizeof(long double)),
                             long long, long double>::type max_size_t;

    // 打印测试结果
    std::cout << "\nTesting std::conditional:\n";
    std::cout << "Type1 is int: " << std::is_same<Type1, int>::value << std::endl;
    std::cout << "Type2 is float: " << std::is_same<Type2, float>::value << std::endl;
    std::cout << "Type3 is long: " << std::is_same<Type3, long>::value << std::endl;
    std::cout << "Type4 is int: " << std::is_same<Type4, int>::value << std::endl;

    // 打印类型大小比较
    std::cout << "\nSize comparison:\n";
    std::cout << "sizeof(long long): " << sizeof(long long) << std::endl;
    std::cout << "sizeof(long double): " << sizeof(long double) << std::endl;
    std::cout << "max_size_t is " << (std::is_same<max_size_t, long long>::value ? "long long" : "long double") << std::endl;
    std::cout << "sizeof(max_size_t): " << sizeof(max_size_t) << std::endl;

    return 0;
}
